using System;
using System.ComponentModel;
using Microsoft.WowAddonStudio.FrameXml.Components.Descriptors;
using Microsoft.WowAddonStudio.FrameXml.Components.Events;
using Microsoft.WowAddonStudio.FrameXml.Serialization;
using NUnit.Framework;
using System.Collections.Generic;

namespace Microsoft.WowAddonStudio.FrameXml.Components.Tests.FrameXmlEvents
{
	[TestFixture]
	public class FrameXmlEventDescriptorCollectionTest
	{
		#region SetUp

		[SetUp]
		public void SetUp()
		{

		}

		#endregion

		#region TearDown

		[TearDown]
		public void TearDown()
		{

		}

		#endregion

		#region Tests

		[Test(Description = "")]
		public void Test_Defaults()
		{
			var eventDescriptor1 = new FrameXmlEventDescriptor(typeof(FrameXmlEventHandler),EventName.OnAnimFinished);
			var eventDescriptor2 = new FrameXmlEventDescriptor(typeof(FrameXmlEventHandler), EventName.OnAttributeChanged);
			var eventDescriptors = new List<EventDescriptor> {eventDescriptor1, eventDescriptor2};

			var collection = new FrameXmlEventDescriptorCollection(eventDescriptors.ToArray());
			Assert.AreEqual(2, collection.Count);
			Assert.IsFalse(collection.ReadOnly);
			Assert.IsTrue(collection.Remove(eventDescriptor1));
			Assert.AreEqual(1, collection.Count);
			collection.Add(eventDescriptor1);
			Assert.AreEqual(2, collection.Count);

			var array = new EventDescriptor[2];

			collection.CopyTo(array, 0);
			Assert.AreEqual(2, array.Length);
			Assert.AreSame(eventDescriptor1, array[1]);
			Assert.AreSame(eventDescriptor2, array[0]);

			Assert.AreSame(eventDescriptor1, collection[1]);
			Assert.AreSame(eventDescriptor2, collection[0]);

			((IList<EventDescriptor>)collection)[1] = new FrameXmlEventDescriptor(typeof(FrameXmlEventHandler), EventName.OnChar);
			Assert.AreEqual("TestEvent3", collection[1].Name);
		}

		#endregion
	}
}